package com.yhsimon.distributed_lock.tmp;

/**
 * @author： YHSimon
 * @date： 2022-09-04 18:21
 */
public class Test {

    public static void main(String[] args) {
        Object lock1 = new Object();
        Object lock2 = new Object();
        new Thread(() -> {
            synchronized (lock1) {
                try {
                    System.out.println("lock1");
                    Thread.sleep(1);
                    synchronized (lock2) {
                        System.out.println("lock2");
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }, "A").start();

        new Thread(() -> {
            synchronized (lock2) {
                try {
                    System.out.println("lock2");
                    Thread.sleep(2);
                    synchronized (lock1) {
                        System.out.println("lock1");
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }, "B").start();
    }


}
